package com.curry.apiprovider.util;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.List;

public class BindResultUtils {


    public static Object validate(BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            List<FieldError> fieldErrors = bindingResult.getFieldErrors();
            StringBuffer stringBuffer = new StringBuffer();
            for (FieldError fieldError : fieldErrors) {
                String defaultMessage = fieldError.getDefaultMessage();
                stringBuffer.append(defaultMessage);
                stringBuffer.append(",");
            }
            return stringBuffer.toString();
        }
        return null;
    }
}
